package com.acyouzi.leetcode.tree;

/**
 * Created by SUN on 2017/9/6.
 */
public class LowestCommonAncestor {
  public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
    if ((p.val <= root.val && q.val >= root.val) || (p.val >= root.val && q.val <= root.val)) return root;
    return p.val < root.val ? lowestCommonAncestor(root.left,p,q) : lowestCommonAncestor(root.right,p,q);
  }
}
